/*
 * Copyright 2020 www.mytijian.com All right reserved. This software is the
 * confidential and proprietary information of www.mytijian.com ("Confidential
 * Information"). You shall not disclose such Confidential Information and shall
 * use it only in accordance with the terms of the license agreement you entered
 * into with www.mytijian.com.
 */
package com.mytijian.task.client.orderrevoke;

import com.mytijian.base.exception.ErrorInfo;
import com.mytijian.order.base.service.OrderReadService;
import com.mytijian.order.base.service.OrderRevokeService;
import com.mytijian.order.base.service.dto.OrderRevokeDTO;
import com.mytijian.order.enums.OrderStatusEnum;
import com.mytijian.order.model.Order;
import com.mytijian.task.enums.TaskTypeEnum;
import com.mytijian.task.model.SubmitTask;
import com.mytijian.task.task.AbstractTaskProcess;
import com.mytijian.task.task.step.DataReader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class OrderRevokeTask extends AbstractTaskProcess<OrderRevokeDTO> {
    @Resource
    private OrderRevokeService orderRevokeService;
    @Autowired
    private OrderReadService orderReadService;
    @Override
    public DataReader dataReader() {
        return new OrderRevokeDataReader();
    }

    @Override
    public ErrorInfo validateBeforeSubmit(SubmitTask task) {
        return null;
    }

    @Override
    public void process(OrderRevokeDTO input) {
        orderRevokeService.revokeOrders(input);
    }

    @Override
    public boolean needProcess(OrderRevokeDTO input) {
        Integer orderId = input.getOrderIds().get(0);
        Order order = orderReadService.getOrderAllInfoByOrderId(orderId);
        return OrderStatusEnum.revoke.getCode() != order.getStatus();
    }


}
